package cn.detu.ln.controller;

import cn.detu.ln.entity.Course;
import cn.detu.ln.service.CourseService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("course")
public class CourseController {
    // 由于controller层需要调用service层方法，因此需要自动装配一个UserService对象
    @Autowired
    private CourseService courseService;
    // GET请求获取用户列表数据
    // localhost:1314/user/selectAll
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, Course course, PageUtil pageUtil, String search){
        switch (url){
            case "selectAll": return courseService.selectAll();
            // 根据教师工号查询课程信息
            case "selectCourse":return courseService.selectCourse(course.getTeaId());
            case "courseDelete":return courseService.courseDelete(course.getCouId());
            case "queryCourseByPage":return courseService.queryCourseByPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, Course course){
        switch (url){
            case "courseUpdate":return courseService.courseUpdate(course);
            case "courseInsert":return courseService.courseInsert(course);
        }
        return null;
    }
    // localhost:1315/course/queryCourseById/1001
    @GetMapping("queryCourseById/{couId}")
    public Course queryCourseById(@PathVariable("couId") Integer couId){
        return courseService.queryCourseById(couId);
    }
}
